<?php defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

/* JoomLeague League Management and Prediction Game for Joomla!
 * @version $Id: show_matrix.tpl.php 1151 2008-06-24 15:07:32Z julienv $
 * @package Joomleague
 * @copyright Copyright (C) 2007  JoomLeague
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see _joomleague_license.txt
 *  
 * Homepage: http://www.joomleague.de
 * Support: htt://www.joomleague.de/forum/
 * 
 * This file is part of JoomLeague.
 *  
 * JoomLeague is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * Please note that the GPL states that any headers in files and
 * Copyright notices as well as credits in headers, source files
 * and output (screens, prints, etc.) can not be removed.
 * You can extend them with your own credits, though...
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 * The "GNU General Public License" (GPL) is available at
 * http://www.gnu.org/copyleft/gpl.html.
*/ 

?>
<div id="joomleague">
<!-- Header with Project Name-->
<?php
if ((isset($showMatrix_config['show_project_heading']) && $showMatrix_config['show_project_heading'] == "1") OR
   (isset($overall_config['show_project_heading']) && $overall_config['show_project_heading'] == "1")) { ?>
<div class="componentheading" <?php
if ((isset($showMatrix_config['show_print_button']) && $showMatrix_config['show_print_button'] == "1")
   OR (isset($overall_config['show_print_button']) && $overall_config['show_print_button'] == "1")) {
     echo 'style="float:left;"';
    }
?>>
<?php
$heading_type = (isset($overall_config['project_heading_type'])) ? $overall_config['project_heading_type'] : 0;
echo $htmlHelper->showTitle($joomleague, $heading_type); ?></div>
<!-- Druckfunktion -->
<?php if ((isset($showMatrix_config['show_print_button']) && $showMatrix_config['show_print_button'] == "1") OR
      (isset($overall_config['show_print_button']) && $overall_config['show_print_button'] == "1")) {
$htmlHelper->PrintIcon( $row, $params, false, '' );
};?>
<!-- Druckfunktion Ende -->
<?php } ?>
<!-- Header END -->

<?php if (isset($showMatrix_config['show_section_heading']) && $showMatrix_config['show_section_heading']==1) { ?>
<!-- Bereichs�berschrift z.B Tabelle, Tippabgabe usw. bei Bedarf mit Drucksymbol -->
<table width="100%" class="contentpaneopen">
	<tr>
		<td class="contentheading">
		  <?php 
		    echo _JL_MATRIX;
		    if ($divisionid) echo " ".$division->name;
		  ?>
		</td>
	</tr>
</table>
<!-- Bereichs�berschrift Ende -->
<?php
}
?>
<br /><div style="width:99%;height:auto;overflow:auto;text-align:center;" align="center">
<?php
  $matrix = '<table width="96%" align="center" border="0" cellpadding="5" cellspacing="0">';
  $k=1;
  $crosstable_icons_horizontal = (isset($showMatrix_config['crosstable_icons_horizontal'])) ? $showMatrix_config['crosstable_icons_horizontal'] :0;
  $crosstable_icons_vertical = (isset($showMatrix_config['crosstable_icons_vertical'])) ? $showMatrix_config['crosstable_icons_vertical'] :0;
  
  $k_r = 0; // count rows 
  foreach( $teams as $team_row_id => $team_row ) {
    if ($k_r == 0) {
    	//write the first row
    	if ($crosstable_icons_horizontal) {
    	 $matrix .=  '<th align=\"center\">&nbsp;</th>';
    	}
    	else $matrix .=  "<th width=\"50\" class=\"sectiontableheader\" align=\"center\">&nbsp;</th>";
    	
    	foreach( $teams as $team_row_header ) {
    	 $header = '<th width="50" class="sectiontableheader" align="center">
		    	         <a href="'.sefRelToAbs(JL_COMPONENT_LINK
		    	                 .'&amp;func=showClubInfo'
		    	                 .'&amp;cid='.$team_row_header->club_id.JL_ITEMID_SUFFIX
		    	                 .'&amp;p='.$joomleague->id).'"'
		    	          .' title="'._JL_PAGE_TITLE_CLUB_INFO.' '.$team_row_header->name.'">';
	     if ($crosstable_icons_horizontal) {
	       $header .= '<img src="'.$team_row_header->logo_small.'" 
	                        alt="'._JL_PAGE_TITLE_CLUB_INFO.' '.$team_row_header->name.'" 
	                        title="'._JL_PAGE_TITLE_CLUB_INFO.' '.$team_row_header->name.'"/>';
	     }
	     else $header .= $team_row_header->short_name;
		   $header .= "</a></th>";
		   $matrix .=  $header;
    	}
    }
  	
    $class = ( $k_r % 2 == 0 )? 'sectiontableentry1' : 'sectiontableentry2';
    $trow = $team_row;
    $matrix .= "<tr class =\"$class\">";
    
    $k_c = 0; //count columns
    foreach( $teams as $team_col_id => $team_col ) {
    	
    	if ($k_c == 0) {
    		//write the first column
    		$value = sprintf("<th width=\"50\" align=\"left\"><b><a href='"
                .sefRelToAbs(JL_COMPONENT_LINK."&amp;func=showPlayers&amp;ttid=$trow->teamtoolid".JL_ITEMID_SUFFIX."&amp;p=$joomleague->id")
                ."' title=\"%s %s\">%s</a></b></th>",_JL_PAGE_TITLE_PLAYERS,$trow->name,$trow->short_name);
    	  $matrix .=  $value;
    	}
      else if($k_c == 0 && $crosstable_icons_vertical == 1) {
        $value = sprintf("<th width=\"50\" align=\"center\"><a href='"
              .sefRelToAbs(JL_COMPONENT_LINK."&amp;func=showPlayers&amp;ttid=$trow->teamtoolid".JL_ITEMID_SUFFIX."&amp;p=$joomleague->id")
              ."'><img src=\"$trow_icon\" alt=\"%s %s\" title=\"%s %s\"/></a></th>",$trow->name,_JL_PAGE_TITLE_PLAYERS,$trow->name,_JL_PAGE_TITLE_PLAYERS,$trow->name,_JL_PAGE_TITLE_PLAYERS,$trow->name,_JL_PAGE_TITLE_PLAYERS); //vertical picture columns      
        $matrix .=  $value;
      }
    	
      $tcol = $team_col;
      $match_result = "&nbsp;";
      
      // find the corresponding game
      foreach($results as $result){		
        if($result->matchpart1 == $team_row->id && $result->matchpart2 == $team_col->id){
			    // $match->decision ist f�r die gr�ne Tischentscheidung ma�gebend --> stefan47110815 (23.04.2007)
			    if ($result->decision==0) {
			      $e1=$result->e1;
			 	    $e2=$result->e2;
			    }
			    else {
			     $e1=$result->v1;
			 	    $e2=$result->v2;
	             if (!isset($result->v1)) { $e1 = 'X'; }
	             if (!isset($result->v2)) { $e2 = 'X'; }
			    }
			    
					if ($result->show_report==1&&$e1!=""&&$e2!="") {
					  $match_result = '<a href="'
					                  .sefRelToAbs(JL_COMPONENT_LINK."&amp;func=showReport&amp;mid=$result->match_id".JL_ITEMID_SUFFIX."&amp;p=$joomleague->id").'">'.$e1.':'.$e2.'</a>';
					}
					else if ($e1!=""&&$e2!="") $match_result = "$e1:$e2";    // $result->e1 und $result->e2 ge�ndert in $e1 und $e2 --> stefan47110815 (23.04.2007)
	        else $match_result = '<a href="'.sefRelToAbs(JL_COMPONENT_LINK."&amp;func=showResultsRank&amp;p=$joomleague->id".JL_ITEMID_SUFFIX
	                              ."&amp;r=$result->matchcode").'"><img src="'.JL_TEMPLATE_FOLDERS_URL.'/images/bullet_black.png" border="0" alt="'.$result->matchcode.'&nbsp;'
	                              ._JL_MATCHDAY.'" title="'.$result->matchcode.'&nbsp;'._JL_MATCHDAY.'" /></a>';
	        break;
        }
      }
      
      $value = "";
      
      if($k_r == $k_c) {
        $value = "<td width=\"50\" align=\"center\" valign=\"middle\"><img src=\"".JL_TEMPLATE_FOLDERS_URL
        ."/images/bullet_red.png\" border=\"0\" alt=\"\"/></td>"; //impossible matches
      }
      else {
        $value = "<td align=\"center\" valign=\"middle\" nowrap=\"nowrap\" title=\"".$trow->name." - ".$tcol->name."\">$match_result</td>\n";
      }
      $matrix .= $value; 
      $k_c++;
    }
    $k_r++;
    $matrix .= "</tr>";
  }
  $matrix .= '</table>';  
  echo $matrix;
  
?>
</div>
<?php if(isset($showMatrix_config['show_help']) && $showMatrix_config['show_help'] == "1") { ;?>
<table width="96%" align="center" border="0" cellpadding="5" cellspacing="0">
  <tr>
   <td align="left"><br /><?php echo _JL_MATRIX_HINT;?></td>
  </tr>
</table>
<?php } ;?>
<!-- Inhalt Ende -->

<!-- Print Button START -->
<?php

if ((isset($showMatrix_config['show_back_button']) && $showMatrix_config['show_back_button'] > 0) OR
(isset($overall_config['show_back_button']) && $overall_config['show_back_button'] > 0)) {
  if ((isset($showMatrix_config['show_back_button']) && $showMatrix_config['show_back_button'] == "1")
  OR (isset($overall_config['show_back_button']) && $overall_config['show_back_button'] == "1")) {
    echo '<div align="left">';
  } else {echo '<div align="right">';}
  $params = & new mosParameters( '' );
  $params->def( 'back_button', true );
  $params->def( 'popup', false );
  mosHTML::BackButton( $params );
  echo "</div>";
};?>
<!-- Print Button END -->
</div>